﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using MediaMonitor.Common;
using Telerik.Web.UI;
using System.Transactions;
using System.Configuration;

namespace MediaMonitor.Users
{
    public partial class UserCart : Adex.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void radGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            OrderDetailCollection colOrderItems = Cart.GetCart();
            radGrid.DataSource = colOrderItems;

        }
        protected void radGrid_PreRender(object sender, EventArgs e)
        {

        }
        protected void radGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Remove")
            {
                string itmID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProdVersionID"].ToString();

                Cart.RemoveItem(Utility.ToInt(itmID));
                radGrid.Rebind();

                AjaxFuncs.MsgBox(this.Page, "Selected item removed from the cart successfully");
            }
        }

        protected void lnkCheckout_Click(object sender, EventArgs e)
        {

            if (!(radGrid.Items.Count > 0))
            {
                lblMsg.Text = "You can't proceed to checkout with an empty cart. You must add a video to cart first.<br>";
                return;
            }

            string msg;
            if (!Cart.Checkout(out msg))
                lblMsg.Text = msg;
            else
                AjaxFuncs.Redirect(this.Page, "orders.aspx");


        }


        protected void lnkClearCart_Click(object sender, EventArgs e)
        {
            Cart.ClearCart();
            radGrid.Rebind();
        }
    }
}